package com.lry.filter.server;

import com.lry.protocol.RpcInvocation;
import com.lry.protocol.RpcMessage;
import com.lry.rpc.netty.RpcContext;
import com.lry.spi.LoadLevel;

import java.util.Map;

@LoadLevel(name = "rpcContext")
public class ServerRpcContextFilter implements ServerFilter {
    @Override
    public void filter(RpcMessage rpcMessage) {
        if(rpcMessage.getBody() instanceof RpcInvocation){
            RpcInvocation rpcInvocation = (RpcInvocation) rpcMessage.getBody();
            Map<String, Object> headMap =  rpcInvocation.getAttachments();
            RpcContext.setMap(headMap);
        }
    }
}
